using System;
using System.DirectoryServices;

namespace Pegasus.DirectoryServices
{
	/// <summary>
	/// Base class for all the pegasus directory objects
	/// </summary>
	public abstract class DirectoryObject
	{
		private DirectoryEntry m_entry = null;

		/// <summary>
		/// Gets or sets the directory entry.
		/// </summary>
		/// <value>The directory entry.</value>
		public DirectoryEntry Entry 
		{
			get
			{
				return m_entry;
			}
		}

		/// <summary>
		/// Attaches the directory entry.
		/// </summary>
		/// <param name="entry">The entry.</param>
		protected void AttachDirectoryEntry( DirectoryEntry entry )
		{
			m_entry = entry;
		}

		/// <summary>
		/// Gets the string property.
		/// </summary>
		/// <param name="property">The property.</param>
		/// <returns></returns>
		protected string GetStringProperty( string property )
		{
			PropertyValueCollection prop = m_entry.Properties[ property ];
			if( prop != null )
			{
				return (string) prop.Value;
			}

			return string.Empty;
		}
	}
}
